#include "wx/wxprec.h"
#if wxUSE_CONTROLS

#include "wx/control.h"

#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/radiobut.h"
#include "wx/statbmp.h"
#include "wx/bitmap.h"
#include "wx/utils.h"       // for wxStripMenuCodes()
#endif

const wxChar wxControlNameStr[] = wxT( "control" );

wxControlBase::~wxControlBase() {
}

bool wxControlBase::Create( wxWindow *parent,
                            wxWindowID id,
                            const wxPoint &pos,
                            const wxSize &size,
                            long style,
                            const wxValidator& wxVALIDATOR_PARAM( validator ),
                            const wxString &name ) {
  bool ret = wxWindow::Create( parent, id, pos, size, style, name );
  #if wxUSE_VALIDATORS
  if( ret ) {
    SetValidator( validator );
  }
  #endif // wxUSE_VALIDATORS
  return ret;
}

bool wxControlBase::CreateControl( wxWindowBase *parent,
                                   wxWindowID id,
                                   const wxPoint& pos,
                                   const wxSize& size,
                                   long style,
                                   const wxValidator& validator,
                                   const wxString& name ) {
  wxCHECK_MSG( parent, false, wxT( "all controls must have parents" ) );
  if( !CreateBase( parent, id, pos, size, style, validator, name ) ) {
    return false;
  }
  parent->AddChild( this );
  return true;
}

wxString wxControlBase::GetLabelText( const wxString& label ) {
  return wxStripMenuCodes( label, wxStrip_Mnemonics );
}

void wxControlBase::Command( wxCommandEvent& event ) {
  ( void )GetEventHandler()->ProcessEvent( event );
}

void wxControlBase::InitCommandEvent( wxCommandEvent& event ) const {
  event.SetEventObject( ( wxControlBase * )this ); // const_cast
  switch( m_clientDataType ) {
    case wxClientData_Void:
      event.SetClientData( GetClientData() );
      break;
    case wxClientData_Object:
      event.SetClientObject( GetClientObject() );
      break;
    case wxClientData_None:
      ;
  }
}

void wxControlBase::SetLabel( const wxString &label ) {
  InvalidateBestSize();
  wxWindow::SetLabel( label );
}

bool wxControlBase::SetFont( const wxFont& font ) {
  InvalidateBestSize();
  return wxWindow::SetFont( font );
}

void wxControlBase::DoUpdateWindowUI( wxUpdateUIEvent& event ) {
  wxWindowBase::DoUpdateWindowUI( event );
  if( event.GetSetText() ) {
    if( event.GetText() != GetLabel() ) {
      SetLabel( event.GetText() );
    }
  }
  #if wxUSE_RADIOBTN
  if( event.GetSetChecked() ) {
    wxRadioButton *radiobtn = wxDynamicCastThis( wxRadioButton );
    if( radiobtn ) {
      radiobtn->SetValue( event.GetChecked() );
    }
  }
  #endif // wxUSE_RADIOBTN
}

#if wxUSE_STATBMP

wxStaticBitmapBase::~wxStaticBitmapBase() {
}

wxSize wxStaticBitmapBase::DoGetBestSize() const {
  wxSize best;
  wxBitmap bmp = GetBitmap();
  if( bmp.Ok() ) {
    best = wxSize( bmp.GetWidth(), bmp.GetHeight() );
  } else {
    best = wxSize( 16, 16 );
  }
  CacheBestSize( best );
  return best;
}

#endif

#endif
